package com.imm.controller;

import com.imm.common.Result;
import com.imm.dto.UserDTO;
import com.imm.pojo.User;
import com.imm.service.IUserService;
import com.imm.utils.BaseContext;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private IUserService userService;

    @PostMapping("/sendMsg")
    public Result<String> sendMsg(@RequestBody User user) {
        return userService.sendMsg(user);
    }

    @PostMapping("/login")
    public Result<User> login(@RequestBody UserDTO userDTO, HttpSession session) {
        return userService.login(userDTO, session);
    }

    @PostMapping("/loginout")
    public Result<String> logout(HttpServletRequest request) {
        BaseContext.setCurrentId(null);
        request.removeAttribute("user");
        return Result.success("退出登录");
    }

}
